// index.js
const app = getApp()
const db = wx.cloud.database()
const {
  envList
} = require('../../envList.js');
Page({
  data: {
    nav: [],
    active: 0,
    showData:[]
  },
  changeActive(e) {
    this.setData({
      active: e.detail.active
    })
  },
  changeShowData(e){
    this.setData({
      showData:e.detail.showData
    });
  },
  toSearch(){
    wx.navigateTo({
      url: "/pages/search/search",
    });
  },
  onLoad() {
    db.collection("tags").where({
      type: "home"
    }).get().then((res) => {
      let list = res.data[0]?.nav;
      if (!res.data.length) {
        wx.request({
          url: app.globalData.baseUrlData + '/yunyuedu/store/navi.json?gender='+app.globalData.sex,
          success: (res) => {
            this.setData({
              nav: res.data.data.navi
            });
            wx.cloud.callFunction({
              name: "getNavData",
              data: {
                nav: res.data.data.navi
              }
            });
          }
        });
      }
      this.setData({
        nav: list
      });
    })
  }
});